<?php
/*
 * [JINYUN!] (C)2001-2099 Jinyunweb.com
 * This is NOT a freeware, use is subject to license terms
 *订单管理
*/
defined('BY_JYA') or exit('error');
$_RQ['op']=$_RQ['op']?$_RQ['op']:'list';
$return=array();
$tabs=array(
	array('op'=>'list','title'=>'车款标明细'),
);
if($_RQ['op']=='list'){
	$return['params']=array();
	$params=array('uniacid'=>$_SESSION['uniacid']);
	if($_RQ['mid']){
		$params['mid']=intval($_RQ['mid']);
		$return['params']['mid']=intval($_RQ['mid']);
	}
	//时间范围
	if($_RQ['createtime']){
		$time_range=cfc('tools')->base64_decode($_RQ['createtime'],$_SESSION['base_key_str']);
		$time_range=json_decode($time_range,true);
		$return['params']['createtime']=$time_range;
		$params['createtime between']=array($time_range['tstart'],$time_range['tend']);
	}
	$pindex = max(1, intval($_RQ['page']));
	if($_RQ['psize']){
		$_SESSION['psize']=$_RQ['psize'];
	}
	$psize = $_SESSION['psize']?:10;
	$list=pdo_getslice('jy_carfee_kuanorder',$params,array($pindex,$psize),$total,$fields,'','id desc');
	foreach($list as &$item){
		$item['member']=cfc('core')->member_show($item['mid']);
		$item['no']=$this->count('gonglog',array('uniacid'=>$_SESSION['uniacid'],'kuanorderid'=>$item['id']),'id');
	}
	$return['list']=$list;
	$totalpage=ceil($total/$psize);
	$totalpage=intval($totalpage);
	$return['totalpage'] =$totalpage;
	$return['params']['page'] =$pindex;
	$htmls=array(
		'type'=>'list',
		'tabs'=>$tabs,
		'list'=>array('data'=>'list','tip'=>'车款标:相当于，购车下款，开启月供！','total'=>$total,'psize'=>$psize,'edit'=>false,'del_one'=>false,'delall'=>false,'list'=>array(
			array('name'=>'member','title'=>'会员信息_Member','type'=>'member'),
			//array('name'=>'goodstitle','title'=>'商品名称','type'=>'string'),
			array('name'=>'months','title'=>'月供期数','type'=>'string'),
			array('name'=>'fee','title'=>'月供额','type'=>'string'),
			array('name'=>'no','title'=>'已供期数','type'=>'string'),
			array('name'=>'status','title'=>'状态','type'=>'radio','options'=>'kuanorder_status'),
			array('name'=>'createtime','title'=>'创建时间','type'=>'time'),
		),'action'=>array(
			array('type'=>'modal','op'=>'check','title'=>'审核','show'=>array('status'=>0)),
			array('type'=>'href','op'=>'gonglog','title'=>'查看月供记录','show'=>array('status'=>1)),
		)),
		'search'=>array(
			array('type'=>'choose','width'=>15,'title'=>'会员id','name'=>'mid','action'=>'member.get_member','choose_title'=>'选择会员'),
			array('type'=>'time_range','width'=>18,'title'=>'创建时间','name'=>'createtime','help'=>''),
		),
	);
	$return['kuanorder_status']=$this->kuanorder_status;	
	$return['htmls']=$htmls;	
	exi($return);
}
if($_RQ['op']=='gonglog'){
	$return['params']=array();
	$kuanorderid=intval($_RQ['id']);
	$params=array('uniacid'=>$_SESSION['uniacid'],'kuanorderid'=>$kuanorderid);
	$pindex = max(1, intval($_RQ['page']));
	if($_RQ['psize']){
		$_SESSION['psize']=$_RQ['psize'];
	}
	$psize = $_SESSION['psize']?:10;
	$list=pdo_getslice('jy_carfee_gonglog',$params,array($pindex,$psize),$total,$fields,'','id desc');
	foreach($list as &$item){
		$item['member']=cfc('core')->member_show($item['mid']);
	}
	$return['list']=$list;
	$totalpage=ceil($total/$psize);
	$totalpage=intval($totalpage);
	$return['totalpage'] =$totalpage;
	$return['params']['page'] =$pindex;
	$htmls=array(
		'type'=>'list',
		'list'=>array('data'=>'list','tip'=>'月供记录','total'=>$total,'psize'=>$psize,'edit'=>false,'del_one'=>false,'delall'=>false,'list'=>array(
			array('name'=>'mid','title'=>'会员id','type'=>'string'),
			array('name'=>'member','title'=>'会员信息_Member','type'=>'member'),
			array('name'=>'no','title'=>'期数','type'=>'string'),
			array('name'=>'year','title'=>'年','type'=>'string'),
			array('name'=>'month','title'=>'月','type'=>'string'),
			array('name'=>'fee','title'=>'额度','type'=>'string'),
			array('name'=>'remark','title'=>'备注','type'=>'string'),
			array('name'=>'createtime','title'=>'创建时间','type'=>'time'),
		)),
	);
	$return['htmls']=$htmls;	
	exi($return);
}
if($_RQ['op']=='check'){
	if($_RQ['postdata']){
		$post=get_postdata();
		$logid=intval($post['id']);
		$status=intval($post['status']);
		if(!$status){
			exi('请选择审核通过还是不通过！','error');
		}
		$this->model('model')->check_kuanorder($logid,$status,$post['checkmsg']);
		exi('审核成功！','','list');
	}
	$item=$this->get('kuanorder',array('id'=>intval($_RQ['id'])));
	if(!$item){
		exi('指定记录不存在！','error');
	}
	$return['item']=$item;
	$return['htmls']=array(
		'type'=>'edit',
		'desc'=>'审核激活月供计划',
		'edit'=>array(
			array('name'=>'status','title'=>'审核','type'=>'radio','options'=>'check_status'),
			array('name'=>'checkmsg','title'=>'不通过原因','type'=>'text','show'=>array('status'=>2)),
		),
	);
	$return['check_status']=$this->check_status;
	exi($return);
}